Landscape Focus Bracketing : perfect near to far focus brackets
Landscape Focus Bracketing Script :Written for/on: G7X :Also works on: Should work on any camera that runs CHDK :Required CHDK build: Anything recent as of 2018 Latest version of script may be downloaded from: https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89 Notes & Usage Unlike macro focus bracketing, where the focus step is the same each time and very small; in landscape focus bracketing we need to calculate the focus for each step. To get the full benefits from this script, it is useful to remember that, ignoring diffraction, at the near and far depth of fields the defocus blur is, by definition, the so-called Circle of Confusion. This blur is usually accepted as being 30 microns for a 35mm full frame camera, and scaled by the crop factor for other formats, eg 11 microns on the G7X. Having said this, 30 microns, is not the 'best focus' quality but you will not see the differences on your Facebook images, only when you create high (focus) quality prints that will be scrutinised close up, eg in a competition. As you need a line pair (black and white pixels, to see a line, it is not sensible to consider CoCs less than, say, 2 sensor pixels. Finally, defocus blur is, of course, zero at the point of focus. Also, at the Hyperfocal distance (H), the blur at infinity will be the CoC. It is useful to note that any blur at infinity can be 'dialed in', by simply focusing at a distance either side of H. Thus, on my G7X, with a CoC of 11 microns, if I focus at twice H, then the infinity blur will be CoC/2. Likewise, at H/4, the infinity blur will be 4*CoC. The script scales everything relative to H and the following illustrates how focus blur varies with respect to H. When focus bracketing we must at least ensure the previous image's far DoF is the same as the next image's near DoF: assuming we are focusing near to far as we are in this script. However, many wish to introduce some 'insurance' and have an overlap between the focus brackets. The script provides four options for this overlap: none, 2*CoC/3, CoC/2 and diffraction aware. With diffraction aware overlap, the script calculates the infinity defocus blur to use, that ensures that the defocus blur and diffraction blur, taken together in quadrature, are equal to the CHDK CoC. This overlap blur criterion will never be less than the CHDK set CoC/3. The following illustrates the overlap between image n and n+1. Note that using the overlap feature comes at the cost of needing to take more brackets Having achieved the perfect focus brackets, the script will then create an additional bracket beyond H, ie to cover the infinity focus quality. The options being 2H, 3H or 4H, giving infinity blurs of CoC/2, CoC/3 or CoC/4. If diffraction aware is being used for the overlap, the last image will be around CoC/3. By default the script creates a dark image at the beginning and end of the focus bracket set, to help differentiate the sequence in post. You can turn this off via the menu. At each focus point you can also ask the script to create two additional exposure brackets at either -xEv & +xEv, -xEv & --xEv or at +xEv and ++xEv. X can be 1 or 2Ev from the base exposure. These options cover all the usual exposure bracketing options, eg if in Av mode it would be usual to choose the -/+ logic. If using M mode and following an ETTR approach, then a +/++ logic would be the best choice. Because focus backeting can create large sequences, the script will warn you if the requested bracket sequence is more than your maximum number, which is set to 7, but can be changed as you wish in the script. Finally, the script will create a log file #2306, where the focus positions (mm) for each image will be recorded. You will need to clear out this text file every now and then. To use the script, simply focus on the nearest point of interest and place the camera in manual focus mode. On the G7X you seem to need to do at least one focus operation to get CHDK to set the correct H, thus it is good practice to ensure H is stable, ie by looking at the CHDK DoF feedback. That is constant, for the aperture and focal length you are at, irrespective of focus. The script is started in the normal way, eg by doing a shutter press. Finally, you will find information about this script and other photography matters on my blog at photography.grayheron.net Script Code Save to your /SCRIPTS/ folder as usual -- @title Landscape Bracketing 'Perfect' focus brackets from near to blur defined 'infinity', as a fraction of camera's CoC Plus option of (3) exposure brackets at each focus step of 1Ev or 2Ev, -/0/+ or -/-- or +/++ Camera should be in manual focus mode Latest may be downloaded from: https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89 Tested on a G7X (c) Garry George @chdk_version 1.5 @param p Exposure bracket delta? @default p 0 @values p None 1Ev 2Ev @param j Exposure bracket logic? @default j 0 @values j -/0/+ 0/-/-- 0/+/++ @param g Overlap at? @default g 3 @values g CoC 2CoC/3 CoC/2 diff @param n Max number of focus brackets? @default n 10 @range n 4 30 @param c Script Delay (s) @default c 3 @range c 0 5 @param b Bookends? @default b 1 @values b No Yes @param q Infinity focus quality? @default q 1 @values q CoC/2 CoC/3 CoC/4 @param v Show bracket pos? @default v 1 @values v No Yes @param k Create Log? @default k 1 @values k No Yes -- set_mf(1) -- just in case dof = get_dofinfo() x = dof.focus x_start = x s=get_tv96() base_h = dof.hyp_dist temp = 0 temp1 = 0 temp2 = 0 ok = true error = false fl = 0 log ={} h = base_h -- no overlap. Brackets 'touch' at CHDK CoC if g 1 then -- adjust h to achieve the requested overlap, ie 'touching' at 2*CoC/3 or CoC/2 or at the diffraction aware defocus blur h = (h*3)/2 elseif g 2 then h = 2*h elseif g 3 then -- use diffraction aware overlap: Assume CHDK CoC is total blur, formed in quadrature from defocus and diffraction blurs temp1 = 1000*dof.coc -- total blur set up for imath temp2 = (1342*dof.aperture)/1000 -- set up for imath. From diff_blur = 2.44*0.55*N (um) if temp1 > temp2 then -- can use diffraction aware overlap temp = imath.sqrt(imath.mul(temp1,temp1) - imath.mul(temp2,temp2)) -- diffraction aware defocus blur temp2 = imath.div(temp1,temp) if temp2 > 3000 then h = 3*h print("Warning: High Diff: using CoC/3") else h = (h*temp2)/1000 end else -- very high diffraction condition h = 3*h print("Warning: High Diff: using CoC/3") end end num = ((10*h*(base_h - x))/(2*x*base_h) + 5)/10 if num > n-2 then -- accounting for last 2 brackets for infinity focus ok = false end function bookend() if b 1 then set_tv96(960) shoot() set_tv96(s) end end function refocus(xx) local dis = 0 set_focus(xx) repeat dis = get_focus() sleep(100) -- seems to work on G7X, may need increasing on other cameras until dis get_focus() end function X_bracket() if p ~= 0 then if j 0 then set_tv96(s-96*p) shoot() set_tv96(s+96*p) shoot() elseif j 1 then set_tv96(s+96*p) shoot() set_tv96(s+2*96*p) shoot() else set_tv96(s-96*p) shoot() set_tv96(s-2*96*p) shoot() end set_tv96(s) end end -- Main Section if x_start < base_h and ok then -- start bracketing sleep(c*1000) bookend() refocus(x_start) -- explicitly refocus, just in case dof = get_dofinfo() x = dof.focus fl = dof.focal_length/100 count = 0 last_x = x if k 1 then log+ 1 = "\n"..os.date() end while (x <= h) -- capture brackets: use break to exit loop before h is reached do shoot() X_bracket() temp = get_exp_count().." @ "..x.."mm" if v 1 then print(temp) end if k 1 then log+ 1 = temp end count = count + 1 x = (x*(h*10 - 2*fl))/(h*10 - 2*x*10) if g 3 then if (x <= 0) or (x > h) then break end else if (x <= 0) or (x > base_h) then break end end if x <= last_x then error = true break end last_x = x refocus(x) end if not error then if g 0 then -- distances for the final two images (this if block provides the framework to use other logic) temp1 = base_h temp2 = (q+2)*base_h elseif g 1 then temp1 = base_h temp2 = (q+2)*base_h elseif g 2 then temp1 = base_h temp2 = (q+2)*base_h elseif g 3 then temp1 = h if h > 3*base_h then temp2 = h else temp2 = 3*base_h end end refocus(temp1) shoot() X_bracket() temp = get_exp_count().." @ "..temp1.."mm" if v 1 then print(temp) end if k 1 then log+ 1 = temp end count = count + 1 if temp2 ~= temp1 then refocus(temp2) shoot() X_bracket() temp = get_exp_count().." @ "..temp2.."mm" if v 1 then print(temp) end if k 1 then log+ 1 = temp end count = count + 1 end bookend() temp = count.." focus brackets" print(temp) if k 1 then log+ 1 = temp end temp1 = ((10*dof.coc*base_h)/temp2 + 5)/10 temp = "Infinity blur "..temp1.."um" if k 1 then log+ 1 = temp end if p ~= 0 and k 1 then log+ 1 = "Exposure offset = "..p.."Ev" end else print("Unknown Error") if k 1 then log+ 1 = "Unknown Error" end end else print("Warning") temp2 = num+2 if not ok then temp = "^ max # brackets to "..temp2 else temp = "Already focused beyond H" end print(temp) end refocus(x_start) if k 1 and ok then print_screen(-2306) for i = 1, #log do print(logi.."\n") end end Category:Scripts Category:Focus Bracketing